// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-11-19

package logger

import (
	"context"
	"fmt"
	"gitee.com/go-libs/log/base"
	"gitee.com/go-libs/log/conf"
)

// Debug
// 发送 DEBUG 级日志.
func Debug(text string) {
	if conf.New().DebugOn() {
		singleton.Log(nil, base.LevelDebug, text)
	}
}

// Debugf
// 发送 DEBUG 级日志.
func Debugf(format string, args ...any) {
	if conf.New().DebugOn() {
		singleton.Log(nil, base.LevelDebug, fmt.Sprintf(format, args...))
	}
}

// Debugfc
// 发送 DEBUG 级日志.
func Debugfc(ctx context.Context, format string, args ...any) {
	if conf.New().DebugOn() {
		singleton.Log(ctx, base.LevelDebug, fmt.Sprintf(format, args...))
	}
}

// Error
// 发送 ERROR 级日志.
func Error(text string) {
	if conf.New().ErrorOn() {
		singleton.Log(nil, base.LevelError, text)
	}
}

// Errorf
// 发送 ERROR 级日志.
func Errorf(format string, args ...any) {
	if conf.New().ErrorOn() {
		singleton.Log(nil, base.LevelError, fmt.Sprintf(format, args...))
	}
}

// Errorfc
// 发送 ERROR 级日志.
func Errorfc(ctx context.Context, format string, args ...any) {
	if conf.New().ErrorOn() {
		singleton.Log(ctx, base.LevelError, fmt.Sprintf(format, args...))
	}
}

// Fatal
// 发送 FATAL 级日志.
func Fatal(text string) {
	if conf.New().FatalOn() {
		singleton.Log(nil, base.LevelFatal, text)
	}
}

// Fatalf
// 发送 FATAL 级日志.
func Fatalf(format string, args ...any) {
	if conf.New().FatalOn() {
		singleton.Log(nil, base.LevelFatal, fmt.Sprintf(format, args...))
	}
}

// Fatalfc
// 发送 FATAL 级日志.
func Fatalfc(ctx context.Context, format string, args ...any) {
	if conf.New().FatalOn() {
		singleton.Log(ctx, base.LevelFatal, fmt.Sprintf(format, args...))
	}
}

// Info
// 发送 INFO 级日志.
func Info(text string) {
	if conf.New().InfoOn() {
		singleton.Log(nil, base.LevelInfo, text)
	}
}

// Infof
// 发送 INFO 级日志.
func Infof(format string, args ...any) {
	if conf.New().InfoOn() {
		singleton.Log(nil, base.LevelInfo, fmt.Sprintf(format, args...))
	}
}

// Infofc
// 发送 INFO 级日志.
func Infofc(ctx context.Context, format string, args ...any) {
	if conf.New().InfoOn() {
		singleton.Log(ctx, base.LevelInfo, fmt.Sprintf(format, args...))
	}
}

// Warn
// 发送 WARN 级日志.
func Warn(text string) {
	if conf.New().WarnOn() {
		singleton.Log(nil, base.LevelWarn, text)
	}
}

// Warnf
// 发送 WARN 级日志.
func Warnf(format string, args ...any) {
	if conf.New().WarnOn() {
		singleton.Log(nil, base.LevelWarn, fmt.Sprintf(format, args...))
	}
}

// Warnfc
// 发送 WARN 级日志.
func Warnfc(ctx context.Context, format string, args ...any) {
	if conf.New().WarnOn() {
		singleton.Log(ctx, base.LevelWarn, fmt.Sprintf(format, args...))
	}
}
